import Vue from 'vue'
import Router from 'vue-router'
import Home from '../views/Home.vue'
import FriendsTab from '../views/FriendsTab.vue'
import ChatTab from '../views/ChatTab.vue'
import ProfileTab from '../views/ProfileTab.vue'

Vue.use(Router)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'LoginPage',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/register',
    name: 'RegisterPage',
    component: () => import('../views/Register.vue')
  },
  {
    path: '/home',
    name: 'HomePage',
    component: Home
  },
  {
    path: '/friends',
    name: 'FriendsPage',
    component: FriendsTab
  },
  {
    path: '/chat',
    name: 'ChatTab',
    component: ChatTab
  },
  {
    path: '/profile',
    name: 'ProfilePage',
    component: ProfileTab
  }
]

const router = new Router({
  mode: 'history',
  routes
})

// 全局捕获重复导航错误（Vue2 这样写）
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default router 